package br.com.virtual.base.uteis;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class CriptografiaUtil {

	public static String criptografa(String texto)
			throws NoSuchAlgorithmException, UnsupportedEncodingException {

		MessageDigest md5 = MessageDigest.getInstance("MD5");
		md5.reset();
		return byteArrayToString(md5.digest(texto.getBytes()));
	}

	public static String byteArrayToString(byte[] b)
			throws UnsupportedEncodingException {

		return new String(b, "UTF8");
	}

	public static byte[] StringToByteArray(String s) {

		return s.getBytes();
	}
}